package com.zjh;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zjh.bean.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.awt.*;
import java.io.IOException;
import java.io.Reader;
import java.util.List;

/**
 * @author LiZiQiu
 * @data 2023/2/28
 */
public class Test1 {
    public static void main(String[] args) {
        try {
            Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory build = builder.build(reader,"a2");
            SqlSession session = build.openSession();

            PageHelper.startPage(2,3);
            List<Student> list = session.selectList("com.zjh.dao.StudentDao.getall");
            PageInfo<Student> info = new PageInfo<>(list);

            System.out.println(info.getNextPage());
            for (Student student : info.getList()) {
                System.out.println(student);
            }
            session.close();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
